package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBreedMedication;
import com.yixun.lbx.mapper.farm.BreedMedicationMapper;
import com.yixun.lbx.service.BreedMedicationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BreedMedicationServiceImpl implements BreedMedicationService {
    private final BreedMedicationMapper medicationMapper;

    public BreedMedicationServiceImpl(BreedMedicationMapper medicationMapper) {
        this.medicationMapper = medicationMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return medicationMapper.getCount(map);
    }

    @Override
    public List<YxProBreedMedication> getListByPage(HashMap<String, Object> map) {
        return medicationMapper.getListByPage(map);
    }

    @Override
    public int addMedication(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return medicationMapper.insertSelective(map);
    }

    @Override
    public int updateMedication(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return medicationMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteMedication(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return medicationMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<YxProBreedMedication> getObjByArgs(YxProBreedMedication medication) {
        return medicationMapper.getObjByArgs(medication);
    }

    @Override
    public List<YxProBreedMedication> getSearchListByPage(HashMap<String, String> map) {
        return medicationMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
